﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 策略模式
/// 1.定义一个策略模式的拥有者
/// 2.定义总策略接口
/// 3.定义各个分策略并继承策略接口
/// </summary>
public class DM03Strategy : MonoBehaviour {
    private void Start()
    {
        ContextDM03Strategy context = new ContextDM03Strategy();
        context.SetStrategy(new DMStrategy01());
        context.Cal();   
    }
}
public class ContextDM03Strategy
{
    protected IDM03Strategy m_strategy;
    public void SetStrategy(IDM03Strategy theStrategy)
    {
        m_strategy = theStrategy;
    }
    public void Cal()
    {
        m_strategy.Cal();
    }
}
public interface IDM03Strategy
{
    void Cal();
}
public class DMStrategy01 : IDM03Strategy
{
    public void Cal()
    {
        Debug.Log("strategy 01 calculating....");
    }
}
public class DMStrategy02 : IDM03Strategy
{
    public void Cal()
    {
        Debug.Log("strategy 02 calculating....");
    }
}
